//
//  thirdPersonVC.m
//  HappyStore
//
//  Created by 陈锋 on 16/6/14.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "thirdPersonVC.h"
#import "thirPersonSecCell.h"
#import "HeadView.h"
#import "myProfileCell.h"
#import "PersonProfileCell.h"
#import "hobbyCell.h"
#import "workCell.h"
#import "detailProfile.h"
#import "addJobVC.h"
#import "companyProfileFirCell.h"
#import "companyProfileSecCell.h"
#import "issuedVC.h"
#import "Recruitment.h"
#import "companyMyProfileCell.h"
#import "FriendViewController.h"

@interface thirdPersonVC ()<UITableViewDelegate,UITableViewDataSource>{
    
    NSMutableArray* hobbyArr;
    NSMutableArray * numberArr;
    NSMutableArray *dataArr;
    NSDictionary * pageDict;

}
@property (weak, nonatomic) IBOutlet UIButton *focusBtn;
@property (weak, nonatomic) IBOutlet UIButton *addFendBtn;
@property (weak, nonatomic) IBOutlet UIButton *sendMsgBtn;
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property (weak, nonatomic) IBOutlet UIView *sendMsgXiaoView;
@property (strong, nonatomic) NSMutableDictionary * dicData;
@property (strong, nonatomic) NSArray * dataArr;
@property (strong, nonatomic) NSArray * educationArr;
@property (strong, nonatomic) HeadView *headView;
//关注
@property (strong, nonatomic) UIButton *rightBtnItem;
@property (assign, nonatomic) BOOL isFocus;
@end
static NSString * myProfilecell = @"myProfileCell";
static NSString * hobbycell = @"hobbyCell";
static NSString * workcell = @"workCell";
static NSString * companyProfileFircell = @"companyProfileFirCell";
static NSString * companyProfileSeccell = @"companyProfileSecCell";
static NSString * companyMyProfilecell = @"companyMyProfileCell";
@implementation thirdPersonVC


-(NSArray *)educationArr{
    if (!_educationArr) {
        _educationArr = [NSArray array];
    }
    return _educationArr;
}
-(NSArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSArray array];
    }
    return _dataArr;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    // 设置头视图
    [self setData];
    
    [self sendRequest];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"详情";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
   
    // 注册
    UINib * nib = [UINib nibWithNibName:@"PersonProfileCell" bundle:nil];
    [self.tableview registerNib:nib forCellReuseIdentifier:myProfilecell];
    
    UINib * nib2 = [UINib nibWithNibName:@"hobbyCell" bundle:nil];
    [self.tableview registerNib:nib2 forCellReuseIdentifier:hobbycell];
    
    UINib * nib3 = [UINib nibWithNibName:@"workCell" bundle:nil];
    [self.tableview registerNib:nib3 forCellReuseIdentifier:workcell];
    
    UINib * nib4 = [UINib nibWithNibName:@"companyProfileFirCell" bundle:nil];
    [self.tableview registerNib:nib4 forCellReuseIdentifier:companyProfileFircell];
    
    UINib * nib5 = [UINib nibWithNibName:@"companyProfileSecCell" bundle:nil];
    [self.tableview registerNib:nib5 forCellReuseIdentifier:companyProfileSeccell];
    
    UINib *nib6 = [UINib nibWithNibName:@"companyMyProfileCell" bundle:nil];
    [self.tableview registerNib:nib6 forCellReuseIdentifier:companyMyProfilecell];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"Back" highImage:@"Back"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    [self setUpListenEvent];
    
    NSInteger userId = [self.userId integerValue];
    NSInteger memberId = [allConstMemberid integerValue];
    
    if (userId != memberId) {
        
        if ([self.userType integerValue] == 1 || [self.userType integerValue] == 2) {
            
            //右item
//            UIBarButtonItem *rightItem = [UIBarButtonItem itemWithTarget:self action:@selector(rightBtn) image:@"加好友" highImage:@"加好友"];
//            self.navigationItem.rightBarButtonItem = rightItem;
            //关注按钮
            self.rightBtnItem = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 40)];
            [self.rightBtnItem addTarget:self action:@selector(rightBtn) forControlEvents:UIControlEventTouchUpInside];
            self.rightBtnItem.titleLabel.textAlignment = NSTextAlignmentRight;
            self.rightBtnItem.titleLabel.font = [UIFont systemFontOfSize:14];
            UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightBtnItem];
            self.navigationItem.rightBarButtonItem = rightItem;
            
        }
    }

    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}

//关注
-(void)rightBtn{
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        
        self.isFocus = !self.isFocus;

        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
        //token=rE3F2m8AvfC7CVh85O9q&userId=登陆用户id&targetUuserIid=被关注用户的id
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
        
        if (!self.account) {
            
            [muDicParameters setObject:self.userId forKey:@"targetUuserIid"];//被关注用户的id
            
        }
        
        
        NSString *strURl = @"";
        if (self.isFocus) {
            strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusUser_app_myHome.im.lensum"];
            
//            [self.focusBtn setTitle:@"" forState:0];
        }else {
            strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusUser_cannel_app_myHome.im.lensum"];
            
//            [self.focusBtn setTitle:@"关注" forState:0];
        }
        
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        
//            NSString * jsonStr = [LSHttpTool DataTOjsonString:dicInfo];
            
            if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                if (!self.isFocus) {
                    [self.rightBtnItem setTitle:@"关注" forState:UIControlStateNormal];

                }else{
                    [self.rightBtnItem setTitle:@"已关注" forState:UIControlStateNormal];

                    
                }
            }else {

                self.isFocus = !self.isFocus;
            }
            
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            self.isFocus = !self.isFocus;

            
        }];
    }else {
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
    
    
}

-(void)leftBarButtonItemClick{
    
    FriendViewController * FriendView  = [[FriendViewController alloc]init];
    FriendView.TagerUserId = nil;
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if ([self.userType integerValue] == 1) {//个人
        
        return 5;
    }else if ([self.userType integerValue] == 2) {//企业
        
        return 4;
        
    }else return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([self.userType integerValue] == 1) {//个人
        
        if (section == 0) {
            return 1;
        }else if(section == 1){
            return 1;
        }else if (section == 2){
            return 1;
        }
        else if (section == 3)
        {
            return self.dataArr.count;
        }else if(section == 4){
            return self.educationArr.count;
        }
        else return 0;
        
    }else if ([self.userType integerValue] == 2) {//企业
        
        return 1;
        
    }else return 0;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.section == 0) {
        thirPersonSecCell *cell = [thirPersonSecCell cellWithTableView:tableView];
        
        for (int i = 0 ; i < cell.mtArr.count; i ++) {
            
            UILabel * label = cell.mtArr[i];
            label.text = numberArr[i];
            
        }
        
        return cell;
    }
    
    
   else if (indexPath.section == 1) {
        
        if ([self.userType integerValue] == 1) {//个人
            
            PersonProfileCell * profileCell = [self.tableview dequeueReusableCellWithIdentifier:myProfilecell];
            
            profileCell.classBtn.hidden = NO;
            
            if (pageDict) {
                
                profileCell.classBtn.hidden = NO;
                profileCell.classCount.text = [NSString stringWithFormat:@"%ld",[pageDict[@"sumCount"] integerValue]];
                profileCell.classTitle.text = dataArr[0][@"content"];
                profileCell.classTime.text = dataArr[0][@"createTime"];
                if ([dataArr[0][@"photos"][0] isEqualToString:Default_Image]) {
                    profileCell.classImgConstraint.constant = 0;
                }else{
                    [profileCell.classImg sd_setImageWithURL:[NSURL URLWithString:dataArr[0][@"photos"][0]]];
                }
                
                [profileCell.classBtn addTarget:self action:@selector(jumpClass) forControlEvents:UIControlEventTouchUpInside];
                
            }
            
            if ([self.dicData[@"signature"] isEqualToString:@""] || [self.dicData[@"signature"] isEqualToString:@"null"]) {
                
                profileCell.myprofile.text = @"暂无简介";
                
            }else{
                
                profileCell.myprofile.text = self.dicData[@"signature"];
                
            }
            
            if ([self.dicData[@"goodatfield"] isEqualToString:@""] || [self.dicData[@"goodatfield"] isEqualToString:@"null"]) {
                
                profileCell.focus.text = @"暂无关注领域";
                
            }else{
                
                profileCell.focus.text = self.dicData[@"goodatfield"];
                
            }
            
            if ([self.dicData[@"myneeds"] isEqualToString:@""] || [self.dicData[@"myneeds"] isEqualToString:@"null"]) {
                
                profileCell.needs.text = @"暂无需求";
                
            }else{
                
                profileCell.needs.text = self.dicData[@"myneeds"];
                
            }
            
            return profileCell;
            
        }else if ([self.userType integerValue] == 2) {//企业
            
            companyProfileFirCell * companyProfileFir = [self.tableview dequeueReusableCellWithIdentifier:companyProfileFircell];
            
            if ([self.dicData[@"introduction"] isEqualToString:@"null"] || [self.dicData[@"introduction"] isEqualToString:@""]) {
                
                companyProfileFir.detailLabel.text = @"暂未填写";
                
            }else{
                
                companyProfileFir.detailLabel.text = self.dicData[@"introduction"];
                [companyProfileFir.detailLabel setNumberOfLines:0];
                
            }
            
            
            return companyProfileFir;
            
        }else return nil;
        
        
    }else if (indexPath.section == 2){
        
        if ([self.userType integerValue] == 1) {//个人
            
            hobbyCell * hobbyCell = [self.tableview dequeueReusableCellWithIdentifier:hobbycell];
            
            
            if ([self.dicData[@"hobby"] isEqualToString:@""] || [self.dicData[@"hobby"] isEqualToString:@"null"]) {
                
            }else{
                
                for (int i = 0; i < hobbyArr.count; i++) {
                    
                    if (i != hobbyArr.count -1 && i != hobbyArr.count) {
                        
                        UILabel *label =  hobbyCell.hobby[i];
                        //label.layer.masksToBounds = YES;
                        label.layer.borderColor = [UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f].CGColor;
                        label.layer.borderWidth = 0.5f;
                        //label.layer.cornerRadius = 5.0f;
                        label.backgroundColor = [UIColor colorWithRed:210.0/255.0f green:244.0/255.0f blue:255.0/255.0f alpha:1.0f];
                        label.textColor = [UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f];
                        label.text = hobbyArr[i];
                    }
                    
                }
                
                
            }
            
            return hobbyCell;
            
        }else if ([self.userType integerValue] == 2) {//企业
            
            companyMyProfileCell * profileCell = [self.tableview dequeueReusableCellWithIdentifier:companyMyProfilecell];
            
            profileCell.classBtn.hidden = NO;
            
            if (pageDict) {
                
                profileCell.classBtn.hidden = NO;
                profileCell.classCount.text = [NSString stringWithFormat:@"%ld",[pageDict[@"sumCount"]integerValue]];
                profileCell.classTitle.text = dataArr[0][@"content"];
                profileCell.classTime.text = dataArr[0][@"createTime"];
                [profileCell.classImg sd_setImageWithURL:[NSURL URLWithString:dataArr[0][@"photos"][0]]];
                [profileCell.classBtn addTarget:self action:@selector(jumpClass) forControlEvents:UIControlEventTouchUpInside];
                
            }
            
            
            if ([self.dicData[@"companyField"] isEqualToString:@""] || [self.dicData[@"companyField"] isEqualToString:@"null"]) {
                
                profileCell.focus.text = @"暂无关注领域";
                
            }else{
                
                profileCell.focus.text = self.dicData[@"companyField"];
                
            }
            
            if ([self.dicData[@"companyBusNeeds"] isEqualToString:@""] || [self.dicData[@"companyBusNeeds"] isEqualToString:@"null"]) {
                
                profileCell.needs.text = @"暂无需求";
                
            }else{
                
                profileCell.needs.text = self.dicData[@"companyBusNeeds"];
                
            }
            
            return profileCell;
            
        }else return nil;
        
        
        
    }else if (indexPath.section == 3){
        if ([self.userType integerValue] == 1) {//个人
            
            workCell * workCell = [self.tableview dequeueReusableCellWithIdentifier:workcell];
            NSDictionary * dict = self.dataArr[indexPath.row];
            [workCell.workImg sd_setImageWithURL:[NSURL URLWithString:dict[@"workLogo"]]];
            [workCell.workImg.layer setCornerRadius:(workCell.workImg.frame.size.height/2)];
            [workCell.workImg.layer setMasksToBounds:YES];
            [workCell.workImg setContentMode:UIViewContentModeScaleAspectFill];
            [workCell.workImg setClipsToBounds:YES];
            workCell.workImg.layer.shadowColor = [UIColor whiteColor].CGColor;
            workCell.workImg.layer.shadowOffset = CGSizeMake(4, 4);
            workCell.workImg.layer.shadowOpacity = 0.5;
            workCell.workImg.layer.shadowRadius = 2.0;
            
            workCell.position.text = dict[@"workPosition"];
            workCell.company.text = dict[@"workName"];
            workCell.workTime.text = dict[@"workTime"];
            
            workCell.img1.image = [UIImage imageNamed:@"btn_myD_gz1"];
            workCell.img2.image = [UIImage imageNamed:@"btn_myD_gz2"];
            workCell.img3.image = [UIImage imageNamed:@"btn_myD_gz3"];
            
            return workCell;
            
        }else if ([self.userType integerValue] == 2) {//企业
            companyProfileSecCell * companyProfileSec = [self.tableview dequeueReusableCellWithIdentifier:companyProfileSeccell];
            
            if ([self.dicData[@"companyNature"] isEqualToString:@"null"] || [self.dicData[@"companyNature"] isEqualToString:@""]) {
                
                companyProfileSec.xingZhi.text = @"暂未添加";
            }else{
                
                companyProfileSec.xingZhi.text = self.dicData[@"companyNature"];
                
            }
            if ([self.dicData[@"companyIndustry"] isEqualToString:@"null"] || [self.dicData[@"companyIndustry"] isEqualToString:@""]) {
                
                companyProfileSec.hangYe.text = @"暂未添加";
            }else{
                
                companyProfileSec.hangYe.text = self.dicData[@"companyIndustry"];
                
            }
            if ([self.dicData[@"companyScale"] isEqualToString:@"null"] || [self.dicData[@"companyScale"] isEqualToString:@""]) {
                
                companyProfileSec.guiMo.text = @"暂未添加";
            }else{
                
                companyProfileSec.guiMo.text = self.dicData[@"companyScale"];
                
            }
            if ([self.dicData[@"companyWWW"] isEqualToString:@"null"] || [self.dicData[@"companyWWW"] isEqualToString:@""]) {
                
                companyProfileSec.wangZhan.text = @"暂未添加";
            }else{
                
                companyProfileSec.wangZhan.text = self.dicData[@"companyWWW"];
                
            }
            return companyProfileSec;
            
        }else return nil;
        
        
    }else if (indexPath.section == 4){
        
        workCell * workCell = [self.tableview dequeueReusableCellWithIdentifier:workcell];
        NSDictionary * dict = self.educationArr[indexPath.row];
        [workCell.workImg sd_setImageWithURL:[NSURL URLWithString:dict[@"schoolLogo"]]];
        [workCell.workImg.layer setCornerRadius:(workCell.workImg.frame.size.height/2)];
        [workCell.workImg.layer setMasksToBounds:YES];
        [workCell.workImg setContentMode:UIViewContentModeScaleAspectFill];
        [workCell.workImg setClipsToBounds:YES];
        workCell.workImg.layer.shadowColor = [UIColor whiteColor].CGColor;
        workCell.workImg.layer.shadowOffset = CGSizeMake(4, 4);
        workCell.workImg.layer.shadowOpacity = 0.5;
        workCell.workImg.layer.shadowRadius = 2.0;
        
        workCell.position.text = dict[@"schoolStudy"];
        workCell.company.text = dict[@"schoolName"];
        workCell.workTime.text = dict[@"schoolTime"];
        
        workCell.img1.image = [UIImage imageNamed:@"btn_myD_jy1"];
        workCell.img2.image = [UIImage imageNamed:@"btn_myD_jy2"];
        workCell.img3.image = [UIImage imageNamed:@"btn_myD_gz3"];
        
        return workCell;
    }
    
    
    else return  nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];//取消选中状态
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.userType integerValue] == 1) {//个人
        
        if (indexPath.section == 0) {
            return 60;
        }
        
        else if (indexPath.section == 1) {
            UILabel *label = [[UILabel alloc] init];
            label.numberOfLines = 0;
            if (!self.dicData[@"signature"]) {
                label.text = @"暂无简介";
            }else{
                label.text = self.dicData[@"signature"];
            }
            label.font = [UIFont systemFontOfSize:14];
            CGSize size = [label sizeThatFits:CGSizeMake(228, MAXFLOAT)];
            
            //商务需求
            UILabel *needLabel = [[UILabel alloc] init];
            needLabel.numberOfLines = 0;
            if (!self.dicData[@"myneeds"]) {
                needLabel.text = @"暂无关注领域";
            }else{
                needLabel.text = self.dicData[@"myneeds"];
            }
            needLabel.font = [UIFont systemFontOfSize:14];
            CGSize needSize = [needLabel sizeThatFits:CGSizeMake(228, MAXFLOAT)];
            
            return 130 +size.height + needSize.height;
            //return 170;
        }else if (indexPath.section ==2 ){
            return 80;
        }else if (indexPath.section == 3){
            return 80;
        }else if (indexPath.section == 4){
            return 80;
        }
        else return 0;
    }else if ([self.userType integerValue] == 2) {//企业
        
        if (indexPath.section ==0) {
            return 60;
        }
        
       else if (indexPath.section == 1) {
            companyProfileFirCell * companyProfileFir = [self tableView:tableView cellForRowAtIndexPath:indexPath];
            //设置字体
            UIFont *font = [UIFont fontWithName:@"Arial" size:14];
            companyProfileFir.detailLabel.font = font;
            companyProfileFir.detailLabel.text = self.dicData[@"introduction"];
            CGSize constraint = CGSizeMake(250, 9999.0f);
            
            CGSize size = [companyProfileFir.detailLabel.text sizeWithFont:font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
            
            [companyProfileFir.detailLabel setFrame:CGRectMake(0, 0, size.width, size.height)];
            
            //设置cell自适应高度
            CGRect cellFrame = [companyProfileFir frame];
            cellFrame.origin = CGPointMake(0, 0);
            CGFloat totalHeight = cellFrame.size.height + companyProfileFir.detailLabel.height - 80;
            cellFrame.size.height = totalHeight;
            [companyProfileFir setFrame:cellFrame];
            
            //return companyProfileFir.frame.size.height;
           return size.height + 60;
        }else if (indexPath.section ==2 ){
            companyMyProfileCell *comCell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
            comCell.needs.text = self.dicData[@"companyBusNeeds"];
            CGSize size = [comCell.needs sizeThatFits:CGSizeMake(228, MAXFLOAT)];
            return 140 + size.height;
        }else if (indexPath.section == 3){
            return 150;
        }else return 0;
        
    }else return 0;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 3) {
        if ([self.userType integerValue] == 2) {//企业
            return 10;
        }else{
            return 30;
        }
    }else if (section == 4){
        return 30;
    }else
        return 10;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if ([self.userType integerValue] == 1) {//个人
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableview.width, 30)];
        view.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:247.0/255.0];
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(5, 2, 60, 25)];
        label.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:247.0/255.0];
        label.textColor = [UIColor lightGrayColor];
        label.font = [UIFont systemFontOfSize:14];
        
        
        if (section == 3) {
            
            label.text = @"工作经历";
            [view addSubview:label];
            return view;
            
        }else if (section == 4){
            
            label.text = @"教育经历";
            [view addSubview:label];
            return view;
            
        }else return nil;
    }
    
    else
        return nil;
}
#pragma mark - 发私信
- (IBAction)focusBtn:(UIButton *)sender {
    
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = NO;
    manager.shouldResignOnTouchOutside = NO;
    manager.shouldToolbarUsesTextFieldTintColor = NO;
    manager.enableAutoToolbar = NO;
    
    sessionVC *chatVc = [[sessionVC alloc] init];
    if (_dicData[@"userName"]==nil || [_dicData[@"userName"] isEqualToString:@"null"] ||[_dicData[@"userName"] isEqualToString:@""]) {
        chatVc.title = _dicData[@"account"];
    }else{
        chatVc.title = _dicData[@"userName"];
    }
    
    chatVc.conversationType = ConversationType_PRIVATE;
    chatVc.targetId = _dicData[@"account"];
    chatVc.enableUnreadMessageIcon = YES;
    chatVc.enableNewComingMessageIcon = YES;
    chatVc.defaultHistoryMessageCountOfChatRoom = 50;
    
    self.tabBarController.tabBar.hidden = YES;
    
    [self.navigationController pushViewController:chatVc animated:YES];
    

}
#pragma mark - 发消息

- (IBAction)sendMsg {
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = NO;
    manager.shouldResignOnTouchOutside = NO;
    manager.shouldToolbarUsesTextFieldTintColor = NO;
    manager.enableAutoToolbar = NO;
    
    sessionVC *chatVc = [[sessionVC alloc] init];
    chatVc.title = self.dicData[@"userName"];
    chatVc.conversationType = ConversationType_PRIVATE;
    chatVc.targetId = self.dicData[@"account"];
    chatVc.enableUnreadMessageIcon = YES;
    chatVc.enableNewComingMessageIcon = YES;
    chatVc.defaultHistoryMessageCountOfChatRoom = 50;
    
    self.tabBarController.tabBar.hidden = YES;
    
    [self.navigationController pushViewController:chatVc animated:YES];
}

#pragma mark - 加好友
- (IBAction)callBtn:(UIButton *)sender {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请求添加为好友" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"发送",nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField *nameField = [alert textFieldAtIndex:0];
    nameField.placeholder = @"请输入您的附加信息";
    nameField.keyboardType = UIKeyboardTypeDefault;
    
    [alert showAlertWithCompletionHandler:^(NSInteger buttonIndex) {
        if(buttonIndex == 1){
            UITextField *tf=[alert textFieldAtIndex:0];
            if (tf.text.length > 0) {
                //token=验证用户&userId=用户id&userName=修改用户名&sex=性别&age=年龄&positionName=职位&shipUserId=上属用户id&shipUserType=上属用户类别&address=地址&mobile=联系电话
                NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                [muDicParameters setObject:self.dicData[@"userId"] forKey:@"targetuserId"];
                [muDicParameters setObject:tf.text forKey:@"reason"];
                
                
                NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"isAddFriend_app_social.im.lensum"];
                AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
                    
                } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    
                    NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                    //                    NSString * jsonStr = [LSHttpTool DataTOjsonString:dicInfo];
                    //                                NSLog(@"--------------------json:%@",jsonStr);
                    
                    if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {

                        [self showRightWithTitle:[dicInfo objectForKey:@"msg"] autoCloseTime:2];
                        
                        
                    }else {
                        
                        [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                    }
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                    [self showSingleIconBubble:error.localizedDescription];
                    
                }];
                
            }
        }
    }];

//    if ([_dicData[@"mobile"] isEqualToString:@""] || [_dicData[@"mobile"] isEqualToString:@"null"]) {
//
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"对方并未填写联系方式" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
//        [alert show];
//    }else{
//    
//    UIWebView * callWebView = [[UIWebView alloc]init];
//    NSString * telUrl =[NSString stringWithFormat:@"tel:%@",_dicData[@"mobile"] ];
//    NSURL * telURL = [NSURL URLWithString:telUrl];
//    [callWebView loadRequest:[NSURLRequest requestWithURL:telURL]];
//    [self.view addSubview:callWebView];
//        
//    }
}

-(void)setData{
    self.headView = [[[NSBundle mainBundle] loadNibNamed:@"HeadView" owner:self options:nil] lastObject];
   
    
    [self showRoundProgressWithTitle:@"请稍后..."];
    
    //token=rE3F2m8AvfC7CVh85O9q&userId=9&userType=用户类型 1-个人，2-企业，3-政府
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    
    if (!self.account) {
        
        [muDicParameters setObject:self.userId forKey:@"userId"];//用户类型 1-个人，2-企业，3-政府
         [muDicParameters setObject:self.userType forKey:@"userType"];//验证用户
        
    }else{
    
    [muDicParameters setObject:self.account forKey:@"account"];
        
    }
    
    if (allConstMemberid) {
        [muDicParameters setObject:allConstMemberid forKey:@"MyUserId"];
    }
    
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"MyBasicMessage_app_myHome.im"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//        NSString * jsonStr = [LSHttpTool DataTOjsonString:dicInfo];
//        NSLog(@"--------------------json:%@",jsonStr);

        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            _dicData = dicInfo[@"data"];
            
            if ([_dicData[@"isFriend"] integerValue]) {
                self.sendMsgBtn.hidden = NO;
                self.focusBtn.hidden = YES;
                self.addFendBtn.hidden = YES;
                self.sendMsgXiaoView.hidden = YES;
            }
            
            if([_dicData[@"isFocus"] isEqualToString:@"是"]) {
                [self.rightBtnItem setTitle:@"已关注" forState:UIControlStateNormal];
                self.isFocus = YES;
                
            }else{
                [self.rightBtnItem setTitle:@"关注" forState:UIControlStateNormal];
                self.isFocus = NO;
            }
            
            [self.headView.imgStr sd_setImageWithURL:[NSURL URLWithString:_dicData[@"headPhoto"]]];
            
   
            if (_dicData[@"userName"] == [NSNull null] || [_dicData[@"userName"] isEqualToString:@"null"]) {

                self.headView.nameStr.text = _dicData[@"account"];
                
            }else {
                self.headView.nameStr.text = _dicData[@"userName"];
               
            }
        
            
            if ([self.userType integerValue] == 1) {//个人
                if (_dicData[@"positionName"] == [NSNull null] || [_dicData[@"positionName"] isEqualToString:@"null"]) {
                    self.headView.positionNameStr.text = @" ";
                    
                }else {
                    self.headView.positionNameStr.text = _dicData[@"positionName"];
                }
                
            }else if ([self.userType integerValue] == 2) {//企业
                self.headView.positionNameStr.text = @"";
            }
            //上级
            self.headView.companyUserNameStr.text = [UsedTool userType:_dicData[@"userType"] companyName:_dicData[@"companyName"] userAddress:_dicData[@"address"]];
            CGSize addressSize = [self.headView.companyUserNameStr sizeThatFits:CGSizeMake(screenW - 150, MAXFLOAT)];
            
            
//            if ([_dicData[@"authState"] integerValue] == 2) {
//                self.headView.vStr.image =[UIImage imageNamed:@"yirenzheng"];
//            }else{
//                self.headView.vStr.image =[UIImage imageNamed:@"weirenzheng"];
//            }
            //认证
            self.headView.isAuthState.hidden = [UsedTool authStateImageViewHidden:_dicData[@"authState"]];
            //会员图标
            self.headView.vStr.image = [UsedTool setVipimage:_dicData[@"vipLevel"]];
            if ([_dicData[@"mobile"] isEqualToString:@"null"] || [_dicData[@"mobile"] isEqualToString:@""]) {
                
                self.headView.phoneStr.text = @"暂未添加";
            }else{
                self.headView.phoneStr.text = _dicData[@"mobile"];
            }
            if ([_dicData[@"email"] isEqualToString:@""] || [_dicData[@"email"] isEqualToString:@"null"]) {
                
                self.headView.emailStr.text = @"暂未添加邮箱";
                
            }else{
                self.headView.emailStr.text = _dicData[@"email"];
            }
            
            CGSize nameSize = [self.headView.nameStr sizeThatFits:CGSizeMake(MAXFLOAT, 20)];
            if (self.headView.nameConstraint.constant == 220) {
                if (nameSize.width > 192) {
                    self.headView.nameConstraint.constant -= 192;
                }else{
                    self.headView.nameConstraint.constant -= nameSize.width;
                }
            }
            
            CGSize nameSizeCon = [self.headView.nameStr sizeThatFits:CGSizeMake(192, MAXFLOAT)];
            if (addressSize.height >= 30) {
                self.headView.frame = CGRectMake(0, 0, screenW, self.headView.height - self.headView.nameStr.height + nameSizeCon.height + addressSize.height - 30);
            }else{
                self.headView.frame = CGRectMake(0, 0, screenW, self.headView.height - self.headView.nameStr.height + nameSizeCon.height);
            }
            
            
            
//            if ([_dicData[@"isFocus"] isEqualToString:@"是"]) {
//                [self.focusBtn setTitle:@"" forState:0];
//                self.focusBtn.selected = YES;
//            }
            
            self.dataArr = _dicData[@"work"];
            self.educationArr = _dicData[@"education"];
            hobbyArr = [[self.dicData[@"hobby"] componentsSeparatedByString:@","] copy];
            
            NSMutableArray * othernumberArr = [NSMutableArray array];

            [othernumberArr addObject:_dicData[@"projectNumber"]];
            [othernumberArr addObject:_dicData[@"fundsNumber"]];
            [othernumberArr addObject:_dicData[@"activityNumber"]];
            [othernumberArr addObject:_dicData[@"jobhuntingNumber"]];
            [othernumberArr addObject:_dicData[@"serviceNumber"]];
            numberArr = othernumberArr;
            
            if (!self.userType) {
                
                self.userType = _dicData[@"userType"];
            }
            
            if (!self.userId) {
                
                self.userId = _dicData[@"userId"];
                
            }
   
            self.tableview.tableHeaderView = self.headView;
   [self.headView.imgBtn addTarget:self action:@selector(clickHeadImg) forControlEvents:UIControlEventTouchUpInside];

            [self.tableview reloadData];
            [self hideBubble];

        }else {

           [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];

        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
    
}

-(void)clickHeadImg{
    
    NSMutableArray *photos = [NSMutableArray array];
    MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
    MJPhoto *photo = [[MJPhoto alloc] init];
    photo.url = [NSURL URLWithString:_dicData[@"headPhoto"]];
    photo.srcImageView = self.headView.imgStr;
    [photos addObject:photo];
    browser.photos = photos;
    
    [browser show];
    
}

#pragma mark - 监听通知
-(void)setUpListenEvent{
    
    //分类通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clickCategoryChange:) name:@"clicktThirPerson" object:nil];
}
-(void)clickCategoryChange:(NSNotification *)notification{
    NSString * cityName = notification.userInfo[@"category"];
    
    if ([cityName isEqualToString:@"招聘"]) {
        
        UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
        
        Recruitment * recruitment = [sb instantiateViewControllerWithIdentifier:@"Recruitment"];
        
        recruitment.typeTitle = @"招聘求职";
        recruitment.userId = self.dicData[@"userId"];
        recruitment.userType = self.dicData[@"userType"];
        recruitment.navigationController.navigationBarHidden = YES;
        
        [self.navigationController pushViewController:recruitment animated:YES];
        
    }else{
    
    issuedVC * issued = [[issuedVC alloc]init];
    issued.titleStr = cityName;
    issued.userType = self.dicData[@"userType"];
    issued.userId = self.dicData[@"userId"];
    [self.navigationController pushViewController:issued animated:YES];
    
    }
    
    NSLog(@"%@",cityName);
}
-(void)sendRequest{
    NSMutableDictionary * dic = [NSMutableDictionary  dictionary];
    
    if (!self.account) {
        
        dic[@"userId"] = allConstMemberid;
        
        
        dic[@"TagerUserId"] = self.userId;
        
    }else{
    
    dic[@"account"] = self.account;
        
    }
    
    dic[@"page"] = @(1);

    [LSHttpTool sendHttpData:@"getCibdList_app_cibd.im" params:dic success:^(id responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
               //
//        NSString * jsonStr = [LSHttpTool DataTOjsonString:dicInfo];
//        NSLog(@"--------------------json:%@",jsonStr);
        
        
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
         
            pageDict = dicInfo[@"data"][@"page"];
            dataArr = dicInfo[@"data"][@"record"];
            [self.tableview reloadData];
            
        }else{

        }
        
    } failure:^(NSError *error) {

       [self showSingleIconBubble:@"网络连接错误"];

    }];
    
}

#pragma mark - jump
-(void)jumpClass{

    FriendViewController * FriendView = [[FriendViewController alloc]init];
    FriendView.TagerUserId = self.userId;
    
    [self.navigationController pushViewController:FriendView animated:YES];

}
@end
